//
//  FirstViewController.swift
//  Exercise001
//
//  Created by zhangpoor on 17/2/23.
//  Copyright © 2017年 zhangpoor. All rights reserved.
//

import UIKit

import SnapKit
import ZP_Tools

public func getStringAfterChar(_ tString:String ,  _ tChar:Character) -> String? {
    
    var result:String?
    
    for item in tString.characters.indices {
        
        if tString[item] == tChar
        {
            
            if item != tString.endIndex  {
                result = tString.substring(from: tString.index(after: item))
            }
            
            
            
            break
        }
    }
    
    return result
}

public func getStringBeforeChar(_ tString:String ,  _ tChar:Character) -> String? {
    
    var result:String?
    
    
    
    
    for item in tString.characters.indices {
        
        if tString[item] == tChar
        {
            
            if item != tString.endIndex  {
                result = tString.substring(to: item)
            }
            
            
            
            break
        }
    }
    
    return result
}


class FirstViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
        let _v001:UIView = UIView()
        _v001.backgroundColor = UIColor.red;
        
        self.view.addSubview(_v001)
        
        _v001.snp.makeConstraints { (make) in
            make.top.left.equalTo(self.view).offset(60)
            
            make.right.bottom.equalTo(self.view).offset(-60)
        }
        
        /*
        ZP_Helper.init()
        let _abc:String? = nil
        let _str = fomatString(_abc)
        NSLog(_str)
 */
        
        let s:String    = "zhangpoor://abc.ddd.com/sdf/dddd?&aaa=你好&bbb=buhaox"
        let ss:String   = "zhangpoor://"
        let sss         = s.substring(from: ss.endIndex)
        
        
        
        
                
        if let aStr = getStringAfterChar(s, "?")
        {
                //let eStr2 = s.substring(from: )
                //let endIndexA = id.advancedBy(tString.characters.count-1)
                //let rangeOfHelloA = Range(start: startIndex, end: endIndexA)
                //result = tString.substring(with: Range<String.Index>(start: id,end: tString.endIndex))
            print("r:       "+aStr+"\n")
                
        }
        if let bStr = getStringBeforeChar("bbc", "a")
        {
            //let eStr2 = s.substring(from: )
            //let endIndexA = id.advancedBy(tString.characters.count-1)
            //let rangeOfHelloA = Range(start: startIndex, end: endIndexA)
            //result = tString.substring(with: Range<String.Index>(start: id,end: tString.endIndex))
            print("r:       "+bStr+"\n")
            
        }

        
        for index in sss.characters.indices {
            //print("i:\(index)  #\(sss[index])\n")
            let c = sss[index]
            if c == "?"
            {
                print("param:   \(sss.substring(from: sss.index(after: index)))\n")
                
                break
            }
        }
        
        
        
        print("sss:     \(sss)\n")
        if sss == "" {
            print("sss是空字符串\n")
        }
        
        
        
        
        //var u:String? = "a=1,"
        //var u:String?
        //var u:String? = ","
        //var u:String? = "="
        
        var u:String? = "a=1,b=2"
        let ary = u?.components(separatedBy: ",")
        
        print("ary:         \(ary)")
        print("aryCount:    \(ary?.count)")
        
        var dic:[String:String] = [:];
        print("dic:         \(dic)")
        print("dicCount:    \(dic.count)")
        if let pAry = u?.components(separatedBy: ",")
        {
            for p in pAry
            {
                let kv:[String] = p.components(separatedBy: "=")
                if kv.count == 2 {
                    print("kv-0:     \(kv[0])")
                    print("kv-1:     \(kv[1])")
                    dic[kv[0]] = kv[1]
                }
            }
        }
        
        
        
        
       
        
        print("dic:         \(dic)")
        
        
        
        
        let fileUrl = Bundle.main.resourcePath! + "/ZP_RouterInfo.plist"
        
        let dic001 =  NSDictionary(contentsOfFile: fileUrl)
        if var dic002 = dic001 as? [String : Any?] {
            
            if let biz = dic002["BizInfos"] as? [String:Any?]
            {
                for (k,v) in biz {
                    print("k: \(k) , v: \(v)")
                }
            }
            
            /*
            dic002["dddd"] = "dfdsf"
            print("dic002:      \(dic002)")
            */
        }
        
        //var d001:[String:Any]? =  dic001["BizInfos"] as? [String:Any]
        
        //print("dic001:      \(dic001)")
        
        
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

